<template>
  <public-modal
    width="500px"
    :footer="false"
    title="添加MN号"
    modalStyle="visitor-detailModal"
    :publicVisible="publicVisible"
    @handleOk="handleOk"
    @cancel="cancel"
  >
    <div slot="content">
      <a-form-model
        :model="form"
        :rules="rules"
        class="formStyle addFectory"
        layout="inline"
        :labelCol="{ style: 'width: 110px' }"
      >
        <a-form-model-item label="添加设备数量:" prop="num">
          <a-input-number
            size="large"
            :min="1"
            :max="99999"
            style="width: 290px"
            autocomplete="off"
            placeholder="请填写数字"
            v-model.trim="form.num"
          />
        </a-form-model-item>
      </a-form-model>
    </div>
  </public-modal>
</template>
<script>
import publicModal from '@/components/publicModal'
import { addMN } from '@/api/factory'
export default {
  name: 'cancelModel',
  components: { publicModal },
  data() {
    return {
      form: {},
      rules: {
        num: [{ required: true, message: '添加设备数量不能为空', trigger: 'change' }],
      },
      publicVisible: false,
    }
  },
  mounted() {},
  methods: {
    show(records) {
      this.form = { ...records }
      this.publicVisible = true
    },
    async handleOk() {
      try {
        let res = await addMN({ factoryId: this.$route.query.id, num: this.form.num })
        this.$message.success(res.message)
        this.publicVisible = false
        this.$emit('success')
      } catch {
        this.$message.error(res.message)
      }
    },
    cancel() {
      this.publicVisible = false
    },
  },
}
</script>
<style lang="less">
.formStyle {
  padding-bottom: 0;
}
</style>
